package com.zy.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @author LittleDesire
 * @description
 * @date 2022-04-06 周三 17:51
 * @since 17
 */
@Aspect
public class MyAspect {
    //@Before(value = "execution(* com.zy.service.*.doSome(..))")
    public void beforeMethod(){
        System.out.println("前置通知");
    }

    // 使用@After在切入点结尾处切入内容
    // 使用@AfterReturning在切入点return内容之后切入内容（可以用来对处理返回值做一些加工处理）
    //@AfterReturning(value = "execution(* com.zy.service.*.doSome(..))",returning = "msg")
    public void afterReturningMethod(Object msg){
        System.out.println("后置通知"+ msg);
    }

    // 抛异常也会执行  相当于是放在finally语句块当中的   （资源回收）
    @After(value = "execution(* com.zy.service.*.doSome(..))")
    public void afterMethod(){
        System.out.println("最终通知");
    }


    //@Around(value = "execution(* com.zy.service.*.doSome(..))")
    public Object aroundMethod(ProceedingJoinPoint pjp) {
        System.out.println("前");
        Object proceed = null;
        try {
            proceed = pjp.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("后");
        return proceed;
    }

    @AfterThrowing(value = "execution(* com.zy.service.*.doSome(..))",throwing = "e")
    public void throwMethod(Exception e) {
        System.out.println("异常通知"+e);
    }
}
